<template>
    <a href="/add">信息添加</a>
    <h2>管理员登录</h2>
    <a href="/show">信息显示</a>
    <table class="table">
        <thead>
            <tr>
                <th>用户名</th>
                <th>
                    <input type="text" v-model="data.username">
                </th>
            </tr>
            <tr>
                <th>密码</th>
                <th>
                    <input type="password" v-model="data.password">
                </th>
            </tr>
            <tr>
                <th></th>
                <th>
                    <input type="button" value="登录" @click="logg">
                </th>
            </tr>
        </thead>
    </table>
</template>

<script setup lang="ts">
import axios from 'axios';
import { ref } from 'vue';
import { useHyzkaStore } from '@/stores/hycka';
const hycka=useHyzkaStore()
import { useRouter } from 'vue-router';
const router=useRouter()
const data=ref({
    uid:0,
    username:"",
    password:""
})


const logg=()=>{
    axios.get("https://localhost:7090/api/HY/Login",{params:data.value}).then(res=>{
        if(res.data.uid==-1)
    {
        alert('用户名不存在')
        return;
    }
    else
    if(res.data.uid==-2)
    {
        alert('密码错误')
        return;
    }
    else
    {
        alert('登录成功')
        hycka.data.names=data.value.username;
        router.push({path:"/show"})

    }
    })
}
</script>

<style scoped>

</style>